package inner;

class OutClass{
    public int data1 = 1;
    int data2 = 2;
    public static int data3 = 3;


    /**
     * 实例内部类
     * 1.如何获取实例类的对象
     * OuterClass.InnerClass innerClass = new OuterClass().new InnerClass();
     *2.实例内部类当中 不能有静态的成员变量，非要定义，南无只能是static final修饰的
     */

    //实例内部类
    class InnerClass{
        int data1 = 111;
        public int data4 = 4;
        int data5 = 5;
        //public static int data6; error
        static final int data6 = 6;
        public void fun2(){
            OutClass outClass = new OutClass();
//            static final int c = 10; error
            System.out.println("InnerClass::fun2()");
            System.out.println(data1);
            System.out.println(outClass.data1);
            System.out.println(OutClass.this.data1); 
            System.out.println(data2);
            System.out.println(data3);
            System.out.println(data4);
            System.out.println(data5);
            System.out.println(data6);
        }
    }

//    //内部类是可以无限套的(不推荐）
//    class A{
//        class B{
//            class C{}
//
//        }
//    }

    public void test(){
        //public static int b; error
        //static final int c = 0; error
        final int a;
        a = 10;
//        a = 20; error
        System.out.println("OutClass::test()");
    }



}




public class Test {
    public static void main(String[] args) {
        OutClass outClass = new OutClass();//定义一个外部类
        OutClass.InnerClass innerClass = outClass.new InnerClass();//实例化内部类
        OutClass.InnerClass innerClass1 = new OutClass().new InnerClass();
        innerClass.fun2();
    }
}
